package pers.karl.utils.term;

import pers.karl.utils.term.data.Data;
import pers.karl.utils.term.model.Term;

import java.io.IOException;
import java.util.Scanner;

/**
 * 命令行版本
 * @author karl
 */
public class Cmd {

    public static void main(String[] args) throws IOException {

        Data data = new Data();

        showMenu(data);
    }

    private static void showMenu(Data data) {

        while (true) {
            System.out.println("\n-----功能列表-----");
            System.out.println("1、新增术语");
            System.out.println("0、退出");
            System.out.println("其他、查询术语");

            Scanner scanner = new Scanner(System.in);
            String next = scanner.next();

            if("0".equals(next)) {
                break;
            } else if("1".equals(next)) {
                System.out.println("请输入术语名称：");
                String title = scanner.next();

                System.out.println("请输入术语说明：");
                String desc = scanner.next();

                Term term = new Term();
                term.setTitle(title);
                term.setDesc(desc);
                data.saveTerm(term);

                System.out.println("保存完毕");
            } else {
                Term term = data.getTerm(next);
                System.out.println(term.getDesc());
            }
        }

    }


}
